<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:c="http://java.sun.com/jsp/jstl/core">
	<ui:composition template="/templates/padraoJSF.xhtml">
		<ui:define name="barraTitulo">Conceder desconto ao Aluno</ui:define>
		<ui:define name="conteudo">
			
			<!-- Formulario de pesquisa de aluno -->
			<p:dialog header="Pesquisas" width="600" height="500" widgetVar="modalPsq" modal="true" onCloseUpdate="form" fixedCenter="true" effect="FADE">
				<h:form id="formPesquisa">
					<p:tabView id="tabView">
						<p:tab title="Pesquisa de Aluno">
							<fieldset>
								<h:panelGrid columns="2" columnClasses="alinhaEsq width50">
									<h:column>
										<h:outputText value="Nome:" styleClass="textfield" />
									</h:column>
									<h:column>
										<h:inputText value="#{controleConcederDesconto.pesquisaNome}"  size="80" styleClass="textfield" />
									</h:column>								
								</h:panelGrid>
							</fieldset>
							<p:commandLink action="#{controleConcederDesconto.pesquisaAlunoNome}" styleClass="alinhaDir" update=":formResultadoPesquisa">
								<h:graphicImage url="/images/botoes/btnPesquisar.png" class="btnAcoes"/>
							</p:commandLink>									
						</p:tab>
					</p:tabView>
				</h:form>
				<h:form id="formResultadoPesquisa">
					<p:dataTable value="#{controleConcederDesconto.lista}" 
					             id="id_ListaAluno"
					             var="aluno" 
					             paginator="true" 
					             rows="10" 
					             dynamic="true" 
					             rendered="#{not empty controleConcederDesconto.lista}" 
								 firstPageLinkLabel="Primeiro"
					             previousPageLinkLabel="Anterior"
					             nextPageLinkLabel ="Pr&oacute;ximo"
					             lastPageLinkLabel="&Uacute;ltima"
					             emptyMessage="Nenhum resgistro encontrado"
					             errorMessage="Ocorreu um erro"
	    			             selection="#{controleConcederDesconto.aluno}" 
					             selectionMode="single" >
						<p:column styleClass="width60"  >
							<f:facet name="header">
								<h:outputText value="Matr&iacute;cula" />
							</f:facet>
							<h:outputText value="#{aluno.matricula}" />
						</p:column>
						<p:column>
							<f:facet name="header">
								<h:outputText value="Nome" />
							</f:facet>
							<h:outputText value="#{aluno.pessoa.nome}" />
						</p:column>
						<p:column>
							<f:facet name="header">
								<h:outputText value="CPF" />
							</f:facet>
							<h:outputText value="#{aluno.pessoa.CPF}">
								<f:converter converterId="converteCPF" />
							</h:outputText>
						</p:column>
						<p:column resizable="true" styleClass="width80">
							<f:facet name="header">
								<h:outputText value="A&ccedil;&atilde;o" /> 
							</f:facet>
                                 <h:commandLink action="concederDesconto">  
                                         <p:graphicImage url="/images/marcadores/editar.png" alt="Seleciona Aluno"/>  
                                         <f:setPropertyActionListener target="#{controleConcederDesconto.aluno}" value="#{aluno}" />
                                 </h:commandLink>
                     	</p:column>						
					</p:dataTable>
				</h:form>
			</p:dialog>
			<!-- Formulario de pesquisa de aluno Parente-->
			<p:dialog header="Pesquisas Aluno Parente" width="600" height="500" widgetVar="modalPsqParente" modal="true" effect="FADE">
				<h:form id="formPesquisaParente">
					<p:tabView id="tabViewParente">
						<p:tab title="Pesquisa de Aluno">
							<fieldset>
								<h:panelGrid columns="2" columnClasses="alinhaEsq width50">
									<h:column>
										<h:outputText value="Nome:" styleClass="textfield" />
									</h:column>
									<h:column>
										<h:inputText value="#{controleConcederDesconto.pesquisaNome}"  size="80" styleClass="textfield" />
									</h:column>								
								</h:panelGrid>
							</fieldset>
							<p:commandLink action="#{controleConcederDesconto.pesquisaAlunoNomeParente}" styleClass="alinhaDir" update="formResultadoPesquisaParente">
								<h:graphicImage url="/images/botoes/btnPesquisar.png" class="btnAcoes"/>
							</p:commandLink>									
						</p:tab>
					</p:tabView>
				</h:form>
				<h:form id="formResultadoPesquisaParente">
					<p:dataTable value="#{controleConcederDesconto.lista}" 
					             id="id_ListaAlunoParente"
					             var="aluno" 
					             paginator="true" 
					             rows="10" 
					             dynamic="true" 
					             rendered="#{not empty controleConcederDesconto.lista}" 
								 firstPageLinkLabel="Primeiro"
					             previousPageLinkLabel="Anterior"
					             nextPageLinkLabel ="Pr&oacute;ximo"
					             lastPageLinkLabel="&Uacute;ltima"
					             emptyMessage="Nenhum resgistro encontrado"
					             errorMessage="Ocorreu um erro"
	    			             selection="#{controleConcederDesconto.alunoParente}" 
					             selectionMode="single" >
						<p:column styleClass="width60"  >
							<f:facet name="header">
								<h:outputText value="Matr&iacute;cula" />
							</f:facet>
							<h:outputText value="#{aluno.matricula}" />
						</p:column>
						<p:column>
							<f:facet name="header">
								<h:outputText value="Nome" />
							</f:facet>
							<h:outputText value="#{aluno.pessoa.nome}" />
						</p:column>
						<p:column>
							<f:facet name="header">
								<h:outputText value="CPF" />
							</f:facet>
							<h:outputText value="#{aluno.pessoa.CPF}">
								<f:converter converterId="converteCPF" />
							</h:outputText>
						</p:column>
						<p:column resizable="true" styleClass="width80">
							<f:facet name="header">
								<h:outputText value="A&ccedil;&atilde;o" /> 
							</f:facet>
                                 <p:commandLink onclick="modalPsqParente.hide();" update=":formDesconto">  
                                         <p:graphicImage url="/images/marcadores/editar.png" alt="Seleciona Aluno"/>  
                                         <f:setPropertyActionListener target="#{controleConcederDesconto.alunoParente}" value="#{aluno}" />
                                 </p:commandLink>
                     	</p:column>						
					</p:dataTable>
				</h:form>
			</p:dialog>		


			<!-- Dialog com as informacooes detalhada do desconto  -->
			<p:dialog header="Desconto" width="650" height="450" widgetVar="modalDesconto" modal="true" onCloseUpdate="form" fixedCenter="true" effect="FADE">
				<h:form id="formDesconto">
					<p:tabView id="tabViewDesconto"  activeIndex="#{controleConcederDesconto.tabViewIndex}">
						<p:tab title="Detalhe do Desconto">
							<fieldset>
								<h:panelGrid columns="2" columnClasses="alinhaEsq width50">

									<h:column >
										<h:outputText value="Desconto:" styleClass="select" />
									</h:column>
									<h:column >
										<h:selectOneMenu value="#{controleConcederDesconto.alunoDesconto.desconto}" >
										  	<f:selectItem itemLabel="selecione" itemValue="#{controleConcederDesconto.descontoSelecione}"/>
						                    <f:selectItems value="#{controleConcederDesconto.descontos}" var="desconto" itemLabel="#{desconto.descricao}" itemValue="#{desconto}"/>
						                    <f:converter converterId="converteDesconto"/>
										</h:selectOneMenu>
		
									</h:column>
									
									<h:column >
										<h:outputText value="Ano:"/>
									</h:column>
									<h:column >
										<h:inputText size="4" maxlength="4" value="#{controleConcederDesconto.alunoDesconto.ano}" />&nbsp;
										<h:outputText value="Semestre:"/>
										<h:inputText size="2" maxlength="2" value="#{controleConcederDesconto.alunoDesconto.semestre}" />&nbsp;
									</h:column>
		
									<h:column >
										<h:outputText value="Registro RH:"/>
									</h:column>
									<h:column >
										<h:inputText size="10" maxlength="10" value="#{controleConcederDesconto.alunoDesconto.identificador}" />&nbsp;
										<h:outputText value="Ativo:"/>
										<h:selectBooleanCheckbox value="#{controleConcederDesconto.alunoDesconto.ativo}"/>&nbsp;
									</h:column>
		
									<h:column >
										<h:outputText value="Observa&ccedil;&atilde;o:"/>
									</h:column>
									<h:column>
										<h:inputTextarea id="observacaco" value="#{controleConcederDesconto.alunoDesconto.observacao}" rows="5" cols="70" />
									</h:column>	
									
								</h:panelGrid>
							</fieldset>
						</p:tab>
						<p:tab title="Parentesco" rendered="#{controleConcederDesconto.descontoParente}" >
							<fieldset>
								<h:panelGrid columns="2" columnClasses="alinhaEsq width50">
								
									<h:column >
										<h:outputText value="Parentesco:" styleClass="select" />
									</h:column>
									<h:column >
										<h:selectOneMenu value="#{controleConcederDesconto.parentesco}" >
										  	<f:selectItem itemLabel="selecione" itemValue="#{controleConcederDesconto.parentescoSelecione}"/>
						                    <f:selectItems value="#{controleConcederDesconto.parentescos}" var="parentesco" itemLabel="#{parentesco}" itemValue="#{parentesco}"/>
										</h:selectOneMenu>
		
									</h:column>
									
									<h:column>
										<h:outputText value="Matr&iacute;cula:"/>
									</h:column>
									<h:column>
										<h:inputText id="pesquisaMatriculaParente" rendered="#{empty controleConcederDesconto.alunoParente.matricula}" size="15" maxlength="15" value="#{controleConcederDesconto.pesquisaMatricula}" styleClass="upper" >
											<p:ajax update="formDesconto" event="blur" listener="#{controleMatricula.pesquisaAlunoMatricula}" />
										</h:inputText>
										<h:inputText id="matriculaParente" rendered="#{not empty controleConcederDesconto.alunoParente.matricula}" size="15" maxlength="15" value="#{controleConcederDesconto.alunoParente.matricula}" styleClass="upper" >
											<p:ajax update="formDesconto" event="blur" listener="#{controleConcederDesconto.pesquisaAlunoMatricula}" />
										</h:inputText>
										<h:outputLink value="#">
											<h:graphicImage url="/images/botoes/btnPesquisar.png" onclick="modalPsqParente.show();" styleClass="iconesLaterais" />
										</h:outputLink>
									</h:column>		
									<h:column>
										<h:outputText value="Nome:" styleClass="textfield" />
									</h:column>
									<h:column>
										<h:outputText value="#{controleConcederDesconto.alunoParente.pessoa.nome}" styleClass="textfield" />
									</h:column>
									<h:column>
										<h:outputText value="Curso:" styleClass="textfield" />
									</h:column>
									<h:column>
										<h:outputText value="#{controleConcederDesconto.alunoParente.curso.descricao}" styleClass="textfield" />
									</h:column>
									<h:column >
										<p:commandLink update=":formDesconto" actionListener="#{controleConcederDesconto.addParentesco}">
											<h:graphicImage url="/images/botoes/btnAdicionar.png" styleClass="imageField alinhaBotao"/>
										</p:commandLink>
									</h:column>								
								</h:panelGrid>
								<br></br>
								<p:dataTable value="#{controleConcederDesconto.alunoDesconto.alunoDescontoParentes}" 
								             id="id_alunoDescontoParente"
								             var="alunoDescontoParente" 
								             paginator="true" 
								             rows="3" 
								             dynamic="true" 
								             rendered="#{not empty controleConcederDesconto.alunoDesconto.alunoDescontoParentes}" 
											 firstPageLinkLabel="Primeiro"
								             previousPageLinkLabel="Anterior"
								             nextPageLinkLabel ="Pr&oacute;ximo"
								             lastPageLinkLabel="&Uacute;ltima"
								             emptyMessage="Nenhum resgistro encontrado"
								             errorMessage="Ocorreu um erro"
				    			             selection="#{controleConcederDesconto.alunoDescontoParente}" 
								             selectionMode="single" >
									<p:column styleClass="width60"  >
										<f:facet name="header">
											<h:outputText value="Matricula" />
										</f:facet>
										<h:outputText value="#{alunoDescontoParente.alunoParente.matricula}" />
									</p:column>
									<p:column>
										<f:facet name="header">
											<h:outputText value="Nome" />
										</f:facet>
										<h:outputText value="#{alunoDescontoParente.alunoParente.pessoa.nome}" />
									</p:column>
									<p:column resizable="true" styleClass="width20">
										<f:facet name="header">
											<h:outputText value="Parentesco" />
										</f:facet>
										<h:outputText value="#{alunoDescontoParente.paretesco}" />
									</p:column>
									<p:column resizable="true" styleClass="width150">
										<f:facet name="header">
											<h:outputText value="A&ccedil;&atilde;o" /> 
										</f:facet>
											 &nbsp;&nbsp;
				                                <p:commandLink update=":formDesconto" actionListener="#{controleConcederDesconto.removeDescontoParente}">  
													<p:graphicImage url="/images/marcadores/remove.png" alt="Remove o Desconto"/> 
													<f:setPropertyActionListener target="#{controleConcederDesconto.alunoDescontoParente}" value="#{alunoDescontoParente}" />
				                                </p:commandLink>
				                    	</p:column>						
								</p:dataTable>
							</fieldset>
						</p:tab>
					</p:tabView>
					<h:commandLink action="#{controleConcederDesconto.gravarDesconto}" styleClass="alinhaDir">
						<h:graphicImage url="/images/botoes/btnGravar.png" class="btnAcoes"/>
					</h:commandLink>											
				</h:form>
			</p:dialog>
			<!-- Form Principal da aplicacao  -->
			<h:form id="form">
				<p:growl id="messages"/>
				<fieldset>
					<p:panel header="Dados do Aluno">
						<br></br>				
						<h:panelGrid columns="2" columnClasses="alinhaDir">			
							<h:column>
								<h:outputText value="Matr&iacute;cula:"/>
							</h:column>
							<h:column>
								<h:inputText id="pesquisaMatricula" rendered="#{empty controleConcederDesconto.aluno.matricula}" size="15" maxlength="15" value="#{controleConcederDesconto.pesquisaMatricula}" styleClass="upper" >
									<f:ajax render="form" event="blur" listener="#{controleMatricula.pesquisaAlunoMatricula}" />
								</h:inputText>
								<h:inputText id="matricula" rendered="#{not empty controleConcederDesconto.aluno.matricula}" size="15" maxlength="15" value="#{controleConcederDesconto.aluno.matricula}" styleClass="upper" >
									<f:ajax render="form" event="blur" listener="#{controleConcederDesconto.pesquisaAlunoMatricula}" />
								</h:inputText>
								<h:outputLink value="#">
									<h:graphicImage url="/images/botoes/btnPesquisar.png" onclick="modalPsq.show();" styleClass="iconesLaterais" />
								</h:outputLink>
							</h:column>		
							<h:column>
								<h:outputText value="Nome:" styleClass="textfield" />
							</h:column>
							<h:column>
								<h:outputText value="#{controleConcederDesconto.aluno.pessoa.nome}" styleClass="textfield" />
							</h:column>
							<h:column>
								<h:outputText value="Curso:" styleClass="textfield" />
							</h:column>
							<h:column>
								<h:outputText value="#{controleConcederDesconto.aluno.curso.descricao}" styleClass="textfield" />
							</h:column>
						</h:panelGrid>
					</p:panel>
				</fieldset>
				
				<fieldset>
					<p:panel header="Adiciona Desconto">
						<br></br>
						
						<h:panelGrid columns="2" columnClasses="alinhaDir width60" >				
				
							<h:column >
								<h:outputText value="Desconto:" styleClass="select" />
							</h:column>
							<h:column >
								<h:selectOneMenu value="#{controleConcederDesconto.desconto}" >
								  	<f:selectItem itemLabel="selecione" itemValue="#{controleConcederDesconto.descontoSelecione}"/>
				                    <f:selectItems value="#{controleConcederDesconto.descontos}" var="desconto" itemLabel="#{desconto.descricao}" itemValue="#{desconto}"/>
				                    <f:converter converterId="converteDesconto"/>
								</h:selectOneMenu>

							</h:column>
							
							<h:column >
								<h:outputText value="Ano:"/>
							</h:column>
							<h:column >
								<h:inputText size="4" maxlength="4" value="#{controleConcederDesconto.ano}" />&nbsp;
								<h:outputText value="Semestre:"/>
								<h:inputText size="2" maxlength="2" value="#{controleConcederDesconto.semestre}" />&nbsp;
							</h:column>

							<h:column >
								<h:outputText value="Registro RH:"/>
							</h:column>
							<h:column >
								<h:inputText size="10" maxlength="10" value="#{controleConcederDesconto.identificador}" />&nbsp;
								<h:outputText value="Ativo:"/>
								<h:selectBooleanCheckbox value="#{controleConcederDesconto.ativo}"/>&nbsp;
							</h:column>

							<h:column >
								<h:outputText value="Observa&ccedil;&atilde;o:"/>
							</h:column>
							<h:column>
								<h:inputTextarea id="observacaco" value="#{controleConcederDesconto.observacao}" rows="5" cols="70" />
							</h:column>	
							
							<h:column >
								<p:commandLink action="#{controleConcederDesconto.addDesconto}" update="id_descontoResultado">
									<h:graphicImage url="/images/botoes/btnAdicionar.png" styleClass="imageField alinhaBotao"/>
								</p:commandLink>
							</h:column>
						</h:panelGrid>
					</p:panel>
				</fieldset>
			
				<fieldset> 
					<p:panel header="Descontos Concedidos" id="id_descontoResultado">
						<br></br>
						<p:dataTable value="#{controleConcederDesconto.aluno.alunoDescontos}" 
						             id="id_descontos"
						             var="alunoDesconto" 
						             paginator="true" 
						             rows="10" 
						             dynamic="true" 
						             rendered="#{not empty controleConcederDesconto.aluno.alunoDescontos}" 
									 firstPageLinkLabel="Primeiro"
						             previousPageLinkLabel="Anterior"
						             nextPageLinkLabel ="Pr&oacute;ximo"
						             lastPageLinkLabel="&Uacute;ltima"
						             emptyMessage="Nenhum resgistro encontrado"
						             errorMessage="Ocorreu um erro"
		    			             selection="#{controleConcederDesconto.alunoDesconto}" 
						             selectionMode="single" >
							<p:column styleClass="width60"  >
								<f:facet name="header">
									<h:outputText value="C&oacute;digo" />
								</f:facet>
								<h:outputText value="#{alunoDesconto.desconto.codigoDesconto}" />
							</p:column>
							<p:column>
								<f:facet name="header">
									<h:outputText value="Descri&ccedil;&atilde;o" />
								</f:facet>
								<h:outputText value="#{alunoDesconto.desconto.descricao}" />
							</p:column>
							<p:column resizable="true" styleClass="width20">
								<f:facet name="header">
									<h:outputText value="Ano" />
								</f:facet>
								<h:outputText value="#{alunoDesconto.ano}" />
							</p:column>
							<p:column resizable="true" styleClass="width20">
								<f:facet name="header">
									<h:outputText value="Semestre" />
								</f:facet>
								<h:outputText value="#{alunoDesconto.semestre}" />
							</p:column>
							<p:column resizable="true" styleClass="width150">
								<f:facet name="header">
									<h:outputText value="A&ccedil;&atilde;o" /> 
								</f:facet>
	                                 <p:commandLink onclick="modalDesconto.show();" update=":form :formDesconto">
										<p:graphicImage url="/images/marcadores/editar.png" alt="Edita o Desconto"/> 
										<f:setPropertyActionListener target="#{controleConcederDesconto.alunoDesconto}" value="#{alunoDesconto}" />
	                                 </p:commandLink>
									 &nbsp;&nbsp;
	                                 <h:commandLink action="#{controleConcederDesconto.removeDesconto}">  
										<p:graphicImage url="/images/marcadores/remove.png" alt="Remove o Desconto"/> 
										<f:setPropertyActionListener target="#{controleConcederDesconto.alunoDesconto}" value="#{alunoDesconto}" /> 
	                                 </h:commandLink>
	                     	</p:column>						
						</p:dataTable>
					</p:panel>				
				</fieldset>
				<h:commandLink action="#{controleConcederDesconto.gravar}" styleClass="alinhaDir">
					<h:graphicImage url="/images/botoes/btnGravar.png" class="btnAcoes"/>
				</h:commandLink>					
			</h:form>
		</ui:define>
	</ui:composition>
</html>